package MyStack;

public class MinStack<T extends Comparable<T>> {
    private MyArrayStack<T> stack;
    private MyArrayStack<T> minStack;
    public MinStack() {
        this.stack = new MyArrayStack<T>();
        this.minStack = new MyArrayStack<T>();
    }
    public MinStack(int maxNum) {
        this.stack = new MyArrayStack<T>(maxNum);
        this.minStack = new MyArrayStack<T>(maxNum);
    }
    public boolean isFull() {
        return this.stack.isFull();
    }
    public boolean isEmpty() {
        return this.stack.isEmpty();
    }
    public boolean push(T o) {
        if(this.isFull()) {
            return false;
        }
        stack.push(o);
        if(minStack.isEmpty() || o.compareTo(this.minStack.peek()) <= 0) {
            this.minStack.push(o);
        }
        return true;
    }
    public T pop() {
        if(this.isEmpty()) {
            return null;
        }
        Object tmp = this.stack.pop();
        if(this.minStack.peek().equals(tmp)) {
            this.minStack.pop();
        }
        return (T)tmp;
    }
    public T peek() {
        return this.stack.peek();
    }
    public T getMin() {
        return this.minStack.peek();
    }
    public String toString() {
        return "stack: " + this.stack + "|min: " + this.getMin();
    }
}
